package com.lty.jeeg.server.modules.fas.controller;

import com.lty.jeeg.server.common.dto.ResponseInfo;
import com.lty.jeeg.server.common.utils.BeanConverter;
import com.lty.jeeg.server.common.utils.ResponseUtil;
import com.lty.jeeg.server.modules.fas.dto.SupplierDTO;
import com.lty.jeeg.server.modules.fas.vo.SupplierVO;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.lty.jeeg.server.common.page.table.PageTableRequest;
import com.lty.jeeg.server.common.page.table.PageTableResponse;

import com.lty.jeeg.server.modules.fas.model.Supplier;
import com.lty.jeeg.server.modules.fas.service.SupplierService;

import io.swagger.annotations.ApiOperation;

/**
 * @author : LTY
 * @date : 2019-02-12 10:01:41
 * Description : 供应商
 */
@Api(tags = "供应商")
@RestController
@RequestMapping("/supplier")
public class SupplierController {

    private final SupplierService supplierService;

    @Autowired
    public SupplierController(SupplierService supplierService) {
        this.supplierService = supplierService;
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "根据id获取")
    public ResponseInfo get(@PathVariable Long id) {
        return ResponseUtil.success(supplierService.getById(id));
    }

    @PostMapping
    @ApiOperation(value = "保存")
    public ResponseInfo save(@RequestBody SupplierVO supplierVO) {
        return ResponseUtil.success(supplierService.save(BeanConverter.map(supplierVO, SupplierDTO.class)));
    }

    @PutMapping
    @ApiOperation(value = "修改")
    public ResponseInfo update(@RequestBody SupplierVO supplierVO) {
        return ResponseUtil.success(supplierService.update(BeanConverter.map(supplierVO, SupplierDTO.class)));
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除")
    public ResponseInfo delete(@PathVariable Long id) {
        return ResponseUtil.success(supplierService.delete(id));
    }

    @GetMapping("/list")
    @ApiOperation(value = "列表")
    public PageTableResponse list(PageTableRequest request) {
        return supplierService.list(request);
    }

}
